package com.ychong.ychongwidget.ui

import android.os.Bundle
import android.view.Window
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.ychong.library.utils.ScreenUtils
import com.ychong.ychongwidget.R
import com.ychong.ychongwidget.databinding.ActivityImageBannerViewBinding


class ImageBannerViewActivity : AppCompatActivity() {
    private var binding: ActivityImageBannerViewBinding? = null
    private var banners: MutableList<String> = arrayListOf(
        "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2561023669,2911685953&fm=26&gp=0.jpg",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201805%2F26%2F20180526231242_wChzX.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619600086&t=2898827595ea59d82c650f340f4d8b83",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20170601%2F57acd7bc0d304dd18168c1097ace02e2_th.jpg&refer=http%3A%2F%2Fimg.mp.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619600124&t=cfd8935e738054f33ec32b30aa6fc223",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F9167f4230c2c66d2b6b60f8722c1678ac4d743ed1b3bd-xg3GyI_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619600148&t=accbe6127b3d9842a84b66787ad62557",
        "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3706660708,2115286006&fm=26&gp=0.jpg",
        "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=458192623,1716633452&fm=26&gp=0.jpg",
        "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2641602003,914992185&fm=26&gp=0.jpg",
        "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2561023669,2911685953&fm=26&gp=0.jpg",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fstatic.jstv.com%2Fgather%2Fhl%2F20210318%2F38%2F7841821564275970690.jpg&refer=http%3A%2F%2Fstatic.jstv.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619686259&t=ee0fd45d493e2ef848d9c567c9168f98"

    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_image_banner_view)
        initView()
    }

    private fun initView() {
        //这里考虑到不同手机分辨率下的情况
        val params = LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, ScreenUtils.dpToPx(200)
        )
        binding!!.ychBanner.layoutParams = params
        binding!!.ychBanner.setSwitchTime(2000)
        binding!!.ychBanner.init(banners)
    }

    //这里可以按实际需求做调整，在适当的位置可停止轮播，节省资源
    override fun onPause() {
        super.onPause()
        binding!!.ychBanner.cancelTimer()
    }
}